CDT = {
	taskTemp: null,
	currPageNo: 1,
	pageSize: 20
};
//加载任务
function loadTask(pageNo) {
	Tr.get('/admin/buyerWdTask/listAll', {
		'vo.wdShareOrderstatus': $('#status').val(),
		'vo.buyerNick': $('#buyerNick').val(),
		'vo.sellerNick': $('#sellerNick').val(),
		'vo.taskId': $.trim($('#taskId').val()),
		'vo.buyerTaskId': $('#buyerTaskId').val(),
		'vo.pageNo': pageNo,
		'vo.pageSize': CDT.pageSize
	}, function(data) {
		if (data.code != 200) return;
		if (data.results.length <= 0) {
			$('.normTable').hide();
			$('#noMsg').show();
			$('.pagin-btm').hide();
			return;
		}

		var output = Mustache.render(CDT.taskTemp, $.extend(data, {
			isPC: function() {
				return this.device == 'PC';
			},
			orderId: function() {
				if (this.orderId) {
					return this.orderId;
				}
				return '----';
			},
			expressNo: function() {
				if (this.expressNo) {
					return this.expressNo;
				}
				return '----';
			},
			paidFeeStr: function() {
				return $.number(this.paidFee/100, 2);
			},
			rewardIngotStr: function() {
				return $.number(this.rewardIngot/100, 2);
			},
			platIcon: function() {
				return 'plat_' + this.platform;
			},
			modifyTimeStr: function() {
				if (this.modifyTime) {
					return new Date(this.modifyTime).Format('yyyy-MM-dd hh:mm:ss');
				}
				return '----';
			},
			takeTimeStr: function() {
				return new Date(this.takeTime).Format('yyyy-MM-dd hh:mm:ss');
			},
			sellerAdminNameStr:function() {
				return this.sellerAdminName!=null ? this.sellerAdminName:"";
			},
			buyerAdminNameStr:function() {
				return this.buyerAdminName!=null ? this.buyerAdminName:"";
			}
		}));
		$('.normTable').show();
		$('#noMsg').hide();
		$('.pagin-btm').show();
		$('#taskContainer').html(output);
		$('.pagination').pagination(data.totalCount, {
			items_per_page: CDT.pageSize,
			num_display_entries: 5,
			current_page: pageNo,
			num_edge_entries: 2,
			callback: loadTaskCallBack,
			callback_run: false
		});
		CDT.currPageNo = pageNo;
	});
}

function loadTaskCallBack(index, jq) {
	loadTask(index + 1);
}

function cancelTask(id){
    Tr.post('/admin/task/cancelWdShareTask', {id:id}, function(data){
    	if(data.code==200){
    		alert('操作成功');
            loadTask(1);
		}else{
    		alert(data.message);
		}
	});
}

function initBaseBind() {
	$(document).on('click', '.queryBtn', function() {
		loadTask(1);
	});
	$(document).on('click','.cancel',function(){
		var id = $(this).attr('data-id');
        if(!confirm('确认取消该任务？')){
            return;
        }
        cancelTask(id);
	});
	
}

$(function() {
	CDT.taskTemp = $('#taskTemp').remove().val();
	initBaseBind();

	loadTask(1);
});